package com.sample;

import android.app.Application;

import com.ivsign.lib_idcardidentification.IDCardIdentificationManager;

import java.util.ArrayList;
import java.util.List;

/**
 * @description :
 * @autHor :  Jason
 * @date : 2018/8/4 19:27
 */

public class BLEApplication extends Application {


    private static List<BLEDeviceInfo.BleBean> ble;

    @Override
    public void onCreate() {
        super.onCreate();


        IDCardIdentificationManager.getInstance().init(this);


    }

    public static List<BLEDeviceInfo.BleBean> getBle() {

        String dir = SDCardHelper.getSDCardBaseDir() + "/ble/bleConfig.txt";
        if (!SDCardHelper.isFileExist(dir)) {
            BLEDeviceInfo bleDeviceInfo = new BLEDeviceInfo();
            List<BLEDeviceInfo.BleBean> bleBeans = new ArrayList<>();
            BLEDeviceInfo.BleBean bleBean = new BLEDeviceInfo.BleBean();
            bleBean.setMac("DC:2C:26:A3:0A:E1");
            bleBean.setService("0000e455-0000-1000-8000-00805f9b34fb");
            bleBean.setRead("49535343-1e4d-4bd9-ba61-23c647249616");
            bleBean.setWrite("49535343-8841-43f4-a8d4-ecbe34729bb3");
            bleBeans.add(bleBean);
            BLEDeviceInfo.BleBean bleBean3 = new BLEDeviceInfo.BleBean();
            bleBean3.setMac("DF:0C:EE:DD:CC:6F");
            bleBean3.setService("49535343-fe7d-4ae5-8fa9-9fafd205e455");
            bleBean3.setRead("49535343-1e4d-4bd9-ba61-23c647249616");
            bleBean3.setWrite("49535343-8841-43f4-a8d4-ecbe34729bb3");
            bleBeans.add(bleBean3);
            BLEDeviceInfo.BleBean bleBean4= new BLEDeviceInfo.BleBean();
            bleBean4.setMac("*");
            bleBean4.setService("49535343-fe7d-4ae5-8fa9-9fafd205e455");
            bleBean4.setRead("49535343-1e4d-4bd9-ba61-23c647249616");
            bleBean4.setWrite("49535343-8841-43f4-a8d4-ecbe34729bb3");
            bleBeans.add(bleBean4);
            bleDeviceInfo.setBle(bleBeans);
            String gsonString = GsonTools.createGsonString(bleDeviceInfo);
            gsonString = CharactorHandler.jsonFormat(gsonString);
            SDCardHelper.saveFileToSDCardCustomDir(gsonString.getBytes(), "ble", "bleConfig.txt");

        }
        byte[] bytes = SDCardHelper.loadFileFromSDCard(dir);
        String content = new String(bytes);
        BLEDeviceInfo bleDeviceInfo = GsonTools.changeGsonToBean(content, BLEDeviceInfo.class);
        ble = bleDeviceInfo.getBle();

        return ble;
    }
}
